05. Handling User Input

Intro to handling user input Heading

Handling User Input

ND004 C01 L05 05 Intro To Handling User Input

Takeaways

  • Creating, updating, and deleting information from a database requires handling user input on what is being created/updated/deleted. This will be the focus of the rest of this series.

MVC Development: How we'd add Create To-Do item functionality

  • On the view: implement an HTML form
  • On the controller: retrieve the user's input, and manipulate models
  • On the models: create a record in our database, and return the newly created to-do item to the controller
  • On the controller: take the newly created to-do item, and decide how to update the view with it.

What we'll learn in order

  1. How we accept and get user data in the context of a Flask app
  2. Send data in controllers using database sessions in a controller
  3. Manipulating models adding records in SQLAlchemy Models
  4. Direct how the view should update within the controller and views

Controller Quiz

To add functionality for creating to-do items, what are the things we'd develop on the controller layer? Check all that apply.

SOLUTION:
  • Tell the Todo model to create a todo item
  • Direct how the view should update upon creating a new todo item
  • Accept user input from a request